﻿package com.potocrewz.images
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import gs.easing.Expo;
	import gs.easing.Sine;
	import gs.TweenMax;
	
	/**
	 * ...
	 * @author Adrien Lamotte
	 */
	public class SlideShow extends MovieClip
	{
		private var _nombre_images:int;
		private var _tab_images:Array;
		//private var _tab_textes:Array;
		private var _time:int;
		
		private var _current_image:int;
		private var _next_image:int;
		
		private var interval_slide:Timer;
		private var _pause:Boolean = false;
		
		public function SlideShow(pImages:Array, pTime:int = 5000) 
		{
			_nombre_images = pImages.length;
			_tab_images = pImages;
			_time = pTime;
			
			
			for (var i:int = 0; i < _nombre_images; i++) 
			{
				_tab_images[i].alpha = 0;
			}
			//_tab_images[0].alpha = 1;
			
			_current_image = 0;
			
			interval_slide = new Timer(_time);
			interval_slide.addEventListener(TimerEvent.TIMER, Slide);
			interval_slide.dispatchEvent(new TimerEvent(TimerEvent.TIMER));
			interval_slide.start();
		}
		
		private function Slide(e:TimerEvent):void
		{
			if(!pause){
				_next_image = _current_image+1;
				if(_next_image > _nombre_images){_next_image = 1}
				
				appear(_tab_images[(_next_image-1)]);
				
				if((_current_image-1) >= 0){
					disappear(_tab_images[(_current_image-1)]);
				}
				/*appear_text(_tab_textes[(_next_image-1)]);
				disappear_text(_tab_textes[(_current_image-1)]);*/
				
				_current_image = _next_image;
			}
		}
		
		
		private function appear(element){
			TweenMax.to(element, 4, { autoAlpha:1, ease:Sine.easeOut } );
		}

		private function disappear(element){
			TweenMax.to(element, 3, { autoAlpha:0, ease:Sine.easeOut } );
		}
		
		/*private function appear_text(element){
			TweenMax.to(element, 4, { alpha:1, ease:Sine.easeOut } );
			//TweenMax.from(element, 1.2, { x:-10, ease:Sine.easeOut } );
			TweenMax.from(element, 4, {blurFilter:{blurX:70,blurY:70,quality:3},colorMatrixFilter:{brightness:5},glowFilter:{color:0xffffff, alpha:0.8, blurX:50, blurY:50, strength:2}, y:160, ease:Expo.easeOut } );
		}

		private function disappear_text(element){
			TweenMax.to(element, 1, { alpha:0, ease:Sine.easeOut } );
		}*/
		
		
		public function get pause():Boolean { return _pause; }
		
		public function set pause(value:Boolean):void 
		{
			_pause = value;
			if (_pause) {
				//disappear_text(_tab_textes[(_current_image-1)]);
			}
		}
		
		

		
	}
	
}